#include "PrecompiledHeader_Engineer.h"
#include "IMob.h"

/*--------------------------------------------------------------------------*/

IMob::IMob(const glm::vec3& position, float maxHealth, float speed)
{
	Mesh* zombieMesh;
	CResources::getInstance()->Get("ironman", &zombieMesh);

	this->m_mesh = zombieMesh->CreateInstance();

	this->m_mesh->SetParent(CTree::getInstance()->GetRoot());
	this->m_mesh->SetScale(5.0f);
	this->m_mesh->SetRadius(5.0f);
	this->m_mesh->SetPosition(position);

	this->m_aura.SetParent(this->m_mesh);
	this->m_aura.SetRadius(5.0f);

	this->m_health = 1.0f;
	this->m_maxHealth = m_maxHealth;

	float random = rand() % 1000 * 0.001f + 0.75f;

	this->m_speed = speed * random;
}

/*--------------------------------------------------------------------------*/

IMob::~IMob()
{

}

/*--------------------------------------------------------------------------*/

void IMob::SetHealth(float h)
{
	this->m_health = h;

	if (this->m_health > 1.0f)
	{
		this->m_health = 1.0f;
	}
	else if (this->m_health < 0.0f)
	{
		this->m_health = 0.0f;
	}
}

/*--------------------------------------------------------------------------*/

float IMob::GetHealth() const
{
	return this->m_health;
}

/*--------------------------------------------------------------------------*/

void IMob::Damage(float dmg)
{
	float d = dmg / this->m_maxHealth;
	this->SetHealth(this->m_health - d);
}

/*--------------------------------------------------------------------------*/

void IMob::Kill()
{
	this->SetHealth(0.0f);
}

/*--------------------------------------------------------------------------*/

void IMob::Respawn()
{
	this->SetHealth(1.0f);
}

/*--------------------------------------------------------------------------*/

float IMob::GetSpeed() const
{
	return this->m_speed;
}

/*--------------------------------------------------------------------------*/

void IMob::SetSpeed(float f)
{
	this->m_speed = f;
}

/*--------------------------------------------------------------------------*/

const glm::vec3& IMob::GetPosition() const
{
	return this->m_mesh->GetPosition();
}

/*--------------------------------------------------------------------------*/

void IMob::SetPosition(const glm::vec3& pos)
{
	this->m_mesh->SetPosition(glm::vec3(pos.x, pos.y, pos.z));

	this->m_aura.SetDiffuse(Color(rand() % 256, rand() % 256, rand() % 256));
	this->m_aura.SetAmbient(this->m_aura.GetDiffuse());
	this->m_aura.SetSpecular(this->m_aura.GetDiffuse());
}

/*--------------------------------------------------------------------------*/

void IMob::LookAt(float p)
{
	this->m_mesh->SetRotation(glm::vec3(0.0f, 0.0f, p));
}

/*--------------------------------------------------------------------------*/
